package com.dq.controller.api.small;

import com.dq.exception.customException.ApiException;
import com.dq.vo.Vo;
import com.dq.domain.sys.j2cache.Broadcast;
import com.dq.vo.baseVo.VO;
import com.dq.domain.org.Org;
import com.dq.service.AllService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author heshuaijun
 * @date 2019/9/1613:44
 */
@Api(description = "商家通知管理")
@RestController
@RequestMapping("/api/broadCast")
public class ApiBroadCastController extends AllService {
    /**
     * 所有轮播列表
     */
    @ApiOperation("商家通知")
    @GetMapping("/list/{orgId}")
    public VO list(@PathVariable @ApiParam("门店id") Long orgId) throws ApiException {
        Org org = dao.get(Org.class, orgId);
        if (org == null) {
            throw new ApiException("未找到门店");
        }
        List<Broadcast> broadcasts = broadCastRepository.findByOrgAndDeletedFalse(org);
        return new Vo(broadcasts.get(0).toVO(false));
    }
}
